package com.gorkr;

import java.util.HashSet;

import org.junit.jupiter.api.Test;

/**
 * @author 张心宇 <zhangxinyu20@kuaishou.com>
 * Created on 2022-11-07
 */
public class M128LongestConsecutiveSequence {

    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (Integer i : nums){
            set.add(i);
        }
        int max = 0;


        for (Integer i : set){
            if(!set.contains(i-1)){
                int max_i = 1;
                while (set.contains(++i)){
                    max_i++;
                }
                max = Math.max(max, max_i);
            }
        }
        return max;
    }

    @Test
    void test(){
        int[] nums = {0,3,7,2,5,8,4,6,0,1};
        System.out.println(longestConsecutive(nums));
    }
}
